//*******************************************************************************
// COPYRIGHT NOTES
// ---------------
// This is a sample for BCGControlBar Library Professional Edition
// Copyright (C) 1998-2016 BCGSoft Ltd.
// All rights reserved.
//
// This source code can be used, distributed or modified
// only under terms and conditions 
// of the accompanying license agreement.
//*******************************************************************************
//
// ChartCombined3D.cpp : implementation file
//

#include "stdafx.h"
#include "bcgpchartexample.h"
#include "ChartCombined3D.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CChartCombined3DView

IMPLEMENT_DYNCREATE(CChartCombined3DView, CBCGPChartExampleView)

CChartCombined3DView::CChartCombined3DView()
	: CBCGPChartExampleView(CChartCombined3DView::IDD)
{
	//{{AFX_DATA_INIT(CChartCombined3DView)
	m_bShowDataLabels = FALSE;
	m_nDataLabelPosition = 0;
	m_nTransparency = 10;
	m_bShowWalls = TRUE;
	m_bThickWalls = TRUE;
	//}}AFX_DATA_INIT
}

CChartCombined3DView::~CChartCombined3DView()
{
}

void CChartCombined3DView::DoDataExchange(CDataExchange* pDX)
{
	CBCGPChartExampleView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CChartCombined3DView)
	DDX_Control(pDX, IDC_ROTATE, m_wndRotate);
	DDX_Control(pDX, IDC_DATA_LABEL_POSITION, m_wndDataLabelPosition);
	DDX_Control(pDX, IDC_CHART, m_wndChart);
	DDX_Check(pDX, IDC_DATA_LABELS, m_bShowDataLabels);
	DDX_CBIndex(pDX, IDC_DATA_LABEL_POSITION, m_nDataLabelPosition);
	DDX_Control(pDX, IDC_TRANSPARENCY, m_wndTransparency);
	DDX_Slider(pDX, IDC_TRANSPARENCY, m_nTransparency);
	DDX_Check(pDX, IDC_SHOW_WALLS, m_bShowWalls);
	DDX_Control(pDX, IDC_THICK_WALLS, m_wndThickWalls);
	DDX_Check(pDX, IDC_THICK_WALLS, m_bThickWalls);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CChartCombined3DView, CBCGPChartExampleView)
	//{{AFX_MSG_MAP(CChartCombined3DView)
	ON_BN_CLICKED(IDC_DATA_LABELS, OnUpdateChart)
	ON_BN_CLICKED(IDC_ROTATE, OnRotate)
	ON_WM_HSCROLL()
	ON_CBN_SELENDOK(IDC_DATA_LABEL_POSITION, OnUpdateChart)
	ON_BN_CLICKED(IDC_SHOW_WALLS, OnUpdateChart)
	ON_BN_CLICKED(IDC_THICK_WALLS, OnUpdateChart)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CChartCombined3DView diagnostics

#ifdef _DEBUG
void CChartCombined3DView::AssertValid() const
{
	CBCGPChartExampleView::AssertValid();
}

void CChartCombined3DView::Dump(CDumpContext& dc) const
{
	CBCGPChartExampleView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CChartCombined3DView message handlers

void CChartCombined3DView::OnInitialUpdate() 
{
	CBCGPChartExampleView::OnInitialUpdate();
	
	if (m_bIsReady)
	{
		return;
	}

	m_bIsReady = TRUE;

	m_wndTransparency.SetRange(0, 100, TRUE);

	m_wndRotate.GetRotationObject()->SetAutorepeatMode(100);
	m_wndRotate.GetRotationObject()->SetColorTheme(CBCGPRotationObject::BCGP_COLOR_THEME_VISUAL_MANAGER);

	m_wndRotate.GetRotationObject()->EnablePart(CBCGPRotationObject::BCGP_ROTATION_CLOCKWISE, FALSE);
	m_wndRotate.GetRotationObject()->EnablePart(CBCGPRotationObject::BCGP_ROTATION_COUNTER_CLOCKWISE, FALSE);

	m_wndRotate.GetRotationObject()->EnableFlatIcons();

	CBCGPChartVisualObject* pChart = m_wndChart.GetChart();
	ASSERT_VALID(pChart);

	pChart->SetChartTitle(_T("Area, Column and Line:"));

	CBCGPChartSeries* pSeries1 = pChart->CreateSeries(_T("Line"), CBCGPColor(), BCGP_CT_DEFAULT, BCGPChartLine3D);
	CBCGPChartSeries* pSeries2 = pChart->CreateSeries(_T("Column"), CBCGPColor(), BCGP_CT_DEFAULT, BCGPChartColumn3D);
	CBCGPChartSeries* pSeries3 = pChart->CreateSeries(_T("Area"), CBCGPColor(), BCGP_CT_DEFAULT, BCGPChartArea3D);

	pChart->SetThemeOpacity(70);

	COleDateTime today = COleDateTime::GetCurrentTime();

	double arTemp[3][12] = {
		{ 35., 32., 29, 26, 25, 24, 21, 19, 12, 8, 6, 0 },
		{ 5., 12., 19, 20, 15, 12, 14, 23, 18, 14, 10, 7 },
		{ 5., 6., 7, 14, 19, 21, 26, 27, 28, 26, 30, 18 }};

	for (int nMonth = 1; nMonth <= 12; nMonth++)
	{
		COleDateTime date (today.GetYear(), nMonth, 1, 0, 0, 0);

		pSeries1->AddDataPoint(arTemp[0][nMonth - 1]);
		pSeries2->AddDataPoint(arTemp[1][nMonth - 1]);

		pSeries3->AddDataPoint(date.Format(_T("%b")), arTemp[2][nMonth - 1]);
	}

	OnUpdateChart();
}

void CChartCombined3DView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	CBCGPChartExampleView::OnHScroll(nSBCode, nPos, pScrollBar);

	if (pScrollBar != NULL)
	{
		OnUpdateChart();
	}
}

void CChartCombined3DView::OnUpdateChart() 
{
	UpdateData();

	CBCGPChartVisualObject* pChart = m_wndChart.GetChart();
	ASSERT_VALID(pChart);

	// for 3D bars label position can't be changed and is always center
	BOOL bCanChangeLabelPos = m_Feature != CDemoFeature::BCGP_ClusteredBar3D && 
								m_Feature != CDemoFeature::BCGP_Bar3D && 
								m_Feature != CDemoFeature::BCGP_StackedBar3D && 
								m_Feature != CDemoFeature::BCGP_StackedBar1003D;

	m_wndDataLabelPosition.EnableWindow(m_bShowDataLabels && bCanChangeLabelPos);

	pChart->ShowAxisIntervalInterlacing(BCGP_CHART_X_PRIMARY_AXIS, FALSE);
	pChart->ShowAxisIntervalInterlacing(BCGP_CHART_Y_PRIMARY_AXIS);

	pChart->ShowDataLabels(m_bShowDataLabels);

	if (m_bShowDataLabels)
	{
		BCGPChartDataLabelOptions dataLabelOptions = pChart->GetDataLabelOptions();
		dataLabelOptions.m_position = (BCGPChartDataLabelOptions::LabelPosition)m_nDataLabelPosition;

		pChart->SetDataLabelsOptions(dataLabelOptions);
	}

	pChart->SetThemeOpacity(100 - m_nTransparency);

	DWORD dwoFlags = CBCGPChartDiagram3D::DWO_OUTLINE_ALL;

	// Draw walls and floor:
	if (m_bShowWalls)
	{
		dwoFlags |= (CBCGPChartDiagram3D::DWO_DRAW_ALL_WALLS | CBCGPChartDiagram3D::DWO_DRAW_FLOOR);
	}

	m_wndThickWalls.EnableWindow(m_bShowWalls);

	pChart->GetDiagram3D()->SetDrawWallOptions((CBCGPChartDiagram3D::DrawWallOptions)dwoFlags);
	pChart->GetDiagram3D()->SetThickWallsAndFloor(m_bShowWalls && m_bThickWalls);

	pChart->SetDirty();
	pChart->Redraw();
}

void CChartCombined3DView::OnRotate() 
{
	RotateChart(m_wndRotate.GetRotationObject()->GetClicked());
}
